package com.boliq.lol.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.boliq.demo.R;
import com.boliq.lol.bean.NewsArticleBean;
import com.boliq.lol.bean.NewsVideoBean;

import java.util.ArrayList;
import java.util.List;


public class NewsVideoAdapter  extends RecyclerView.Adapter <NewsVideoAdapter.NViewHolder> {


    private List<NewsVideoBean> newsData;
    public NewsVideoAdapter() {
        newsData = new ArrayList<>();
    }
    //构造器，接受数据集
    @NonNull
    @Override
    public NViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_video_article, parent, false);
        return new NViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(@NonNull NViewHolder holder, int position) {
        NewsVideoBean bean = newsData.get(position);
        holder.img.setImageResource(bean.getImg());

    }



    @Override
    public int getItemCount() {
        return newsData.size();
    }

    public void addData(NewsVideoBean bean) {
        newsData.add(bean);
        notifyItemInserted(newsData.size());
    }
    public void addData(List<NewsVideoBean> data) {
        int lastSize = newsData.size();
        newsData.addAll(data);
        notifyItemRangeInserted(lastSize, data.size());
    }

    public class NViewHolder extends RecyclerView.ViewHolder {
        private ImageView img;


        public NViewHolder(View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img_cover);

        }
    }
}
